home *** CD-ROM | disk | FTP | other *** search
- unit IOErrorU;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TForm1 = class(TForm)
- Button1: TButton;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- {$ifdef Ver90}
- //Not defined in Delphi 2
- procedure ShowMessageFmt(const Msg: string; Params: array of const);
- begin
- ShowMessage(Format(Msg, Params));
- end;
- {$endif}
-
- procedure BetterIOError(E: EInOutError);
- var
- EIO: EInOutError;
- begin
- if Assigned(E) then
- begin
- EIO := EInOutError.Create(E.Message);
- EIO.ErrorCode := E.ErrorCode;
- case E.ErrorCode of
- 1, 6..99: EIO.Message := Format('Win32 API error %d:'#13#13'%s',
- [E.ErrorCode, SysErrorMessage(E.ErrorCode)]);
- 2..5, 100, 101, 106: { As descriptive as can be right now };
- 102: EIO.Message := 'File variable not assigned a name with AssignFile';
- 103: EIO.Message := 'File not open';
- 104: EIO.Message := 'File not open for input';
- 105: EIO.Message := 'File not open for output';
- 107..149: EIO.Message := Format('Delphi I/O error %d', [E.ErrorCode]);
- end; //case
- raise EIO
- end
- end;
-
- procedure TForm1.Button1Click(Sender: TObject);
- var
- TF: TextFile;
- begin
- AssignFile(TF, 'c:\SoemFile.Txt');
- try
- Reset(TF);
- try
- //Blah blah
- finally
- CloseFile(TF)
- end //try..finally
- except
- on E: EInOutError do
- BetterIOError(E)
- end //try..except
- end;
-
- end.
-